﻿using ATM.Common;
using ATM.Entities;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ATM.DAO
{
    public class CustomerDAO
    {
        private static SqlConnection con;
        public static string getCustomerName(Account acc)
        {
            string name = "";
            SqlCommand cmd = new SqlCommand("Select * from Customers", DataConnection.GetConnection());
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            da.Fill(dt);
            for (int i = 0; i < dt.Rows.Count; i++)
                if (dt.Rows[i]["CustID"].ToString() == acc.CusID)
                {
                    name = dt.Rows[0]["Name"].ToString();
                }
            DataConnection.CloseConnection();
            return name;
        }

        public static string getCustomerID(string accountID)
        {
            string customerID = "";
            con = DataConnection.GetConnection();
            SqlDataAdapter da = new SqlDataAdapter(String.Format("SELECT * FROM Accounts WHERE ID = '{0}'", accountID), con);
            DataTable dt = new DataTable();
            da.Fill(dt);
            if (dt.Rows.Count > 0)
            {
                customerID = dt.Rows[0]["CusID"].ToString();
            }
            DataConnection.CloseConnection();
            return customerID;
        }
    }
}
